﻿package com.bike.util;

import java.util.List;

public class PageView<T> {
	/** 分页数据 * */
	private List<T> records;
	/** 总页数 * */
	private long totalpage = 1;
	/** 当前页 * */
	private int currentpage = 1;
	/** 总记录数 * */
	private int totalrecord=0;
	/** 每页显示记录数 * */
	private int pagesize=0;
	/** 页码的url* */
	private String pageurl;
	private int startrecord;//起始记录
	private int endrecord;//最后记录
	
	
	/**
	 *当前页和每页显示的数量
	 * @author czh
	 * @Description 
	 * @param
	 */
	public PageView(int page,int pageSize) {
		 this.currentpage=page;
		 this.pagesize=pageSize;
		
	}
	
	public long getPagesize() {
		return pagesize;
	}
	public void setPagesize(int pagesize) {
		this.pagesize = pagesize;
	}
	public List<T> getRecords() {
		return records;
	}
	public void setRecords(List<T> records) {
		this.records = records;
	}
	public long getTotalpage() {
		return totalpage;
	}
	public void setTotalpage(long totalpage) {
		this.totalpage = totalpage;
	}
	public int getCurrentpage() {
		return currentpage;
	}
	public void setCurrentpage(int currentpage) {
		this.currentpage = currentpage;
	}
	public long getTotalrecord() {
		return totalrecord;
	}
	public void setTotalrecord(int totalrecord) {
		this.totalrecord = totalrecord;
		
		long total =this.totalrecord % this.pagesize == 0 ? this.totalrecord
				/ this.pagesize : this.totalrecord / this.pagesize + 1;
		if(currentpage>total){
			currentpage=(int) total;
		}
		if(totalrecord==0){
			 startrecord=0;
			 endrecord=0;
		}else{
			startrecord=(currentpage-1)*pagesize+1;
			if(currentpage<total){
				endrecord=startrecord+pagesize-1;
			}else{
				int mod=(int)(this.totalrecord % this.pagesize);
				endrecord=mod==0?startrecord+pagesize-1:startrecord+mod-1;
			}
		}
		setTotalpage(total);
	}
	public String getPageurl() {
		return pageurl;
	}
	public void setPageurl(String pageurl) {
		this.pageurl = pageurl;
	}
	public int getStartrecord() {
		return startrecord;
	}

	public void setStartrecord(int startrecord) {
		this.startrecord = startrecord;
	}

	public int getEndrecord() {
		return endrecord;
	}
	public void setEndrecord(int endrecord) {
		this.endrecord = endrecord;
	}
	 

}
